package test;

import org.xmap.ui.View;
import org.xmap.ui.ViewManager;
import org.xmap.ui.base.Window;
import org.xmap.ui.control.List;
import org.xmap.ui.listener.ItemListener;

public class ListView extends View implements ItemListener {

    protected List l;

    public ListView(View back) {
        super(back);
//        this.setBgColor(0x00ffff88);
        this.setTitleText("列表控件演示");
        this.l = new List(0, 0, 0, 0, Window.ORIENT_LEFT_UP);
        this.l.setScretchMode(Window.SCRETCH_ROW | Window.SCRETCH_COLUMN);
        this.l.setBgColor(0x00ffff88);
        this.l.setLineColor(0xffb67544);
        this.l.setSelectedColor(0xffff9e0c);
        this.l.setShowTitle(true);
        this.l.setFocus(true);
        this.l.setItemListener(this);
        this.addControls(this.l);
        this.l.addContent(0, "苹果", "苹果", null, "水果", null, "5元", null, false);
        this.l.addContent(0, "草莓", "草莓", null, "水果", null, "6元", null, false);
        this.l.addContent(0, "西瓜", "西瓜", null, "水果", null, "0.5元", null, false);
        this.l.addContent(0, "笔记本", "笔记本", null, "电脑", null, "5000元", null, false);
        this.l.addContent(0, "硬盘", "硬盘", null, "电脑", null, "500元", null, false);
        this.addLeftMenu("添加内容");
        this.addLeftMenu("删除内容");
//        this.addLeftMenu("边框模式", new String[] {"边框显示", "边框隐藏"});
//        this.addLeftMenu("随机图片大小");
//        this.addLeftMenu("背景模式", new String[] {"背景透明", "背景可见"});
        this.setRightMenu("返回");
    }

    public void keySelected(int id, Object obj) {
        this.setTitleText("按键选中：" + obj);
    }

    public void pointerSelected(int id, Object obj) {
        this.setTitleText("触笔选中：" + obj);
    }

    public void pointerDoubleSelected(int id, Object obj) {
    }
//    public void timeInterrupted() {
////        this.ig.setLineColor((int) System.currentTimeMillis());
//    }
//    public boolean keyEvent(boolean flag, int keyCode, int gameAction) {
//        if (flag) {
//            Env.screenWidth = (int) (Math.abs(System.currentTimeMillis()) % ViewManager.instance.getWidth());
//            Env.screenHeight = (int) (Math.abs(System.currentTimeMillis()) % ViewManager.instance.getHeight());
//            return true;
//        } else {
//            return false;
//        }
//    }

    public void commandEvent(String command, Window sender) {
        if (command.equals("添加内容")) {
            this.l.addContent(0, "测试", "测试一", null, "测试二", null, "测试三", null, false);
        } else if (command.equals("删除内容")) {
            this.l.removeSelected();
        } else if (command.equals("返回")) {
            ViewManager.instance.setView(this.back, View.ANIMATION_LEFT_TO_RIGHT);
        }
    }
}
